package bancosys.tec.utils.date;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

/**
 * @author joao.enomoto
 */
public class StoppedClockMustTell {

    private StoppedClock oneClock;
    
    private Date aDate;
    
    private Time aTime;
    
    private Timestamp anInstant;
    
    @Before
    public void setUpClock() {
        this.aDate = new Date(1984, 10, 20);
        this.aTime = new Time(15, 0, 0);
        this.anInstant = new Timestamp(this.aDate, this.aTime);
        this.oneClock = new StoppedClock(this.anInstant);
    }
    
    @Test
    public void aFixedDate() {
        assertEquals(this.aDate, this.oneClock.currentDate());
    }
    
    @Test
    public void aFixedTime() {
        assertEquals(this.aTime, this.oneClock.currentTime());
    }
    
    @Test
    public void aFixedTimestamp() {
        assertEquals(this.anInstant, this.oneClock.currentTimestamp());
    }
    
    @Test
    public void aDifferentDateAfterBeingAdjusted() {
        Date anotherDate = new Date(1987, 1, 19);
        Timestamp anotherTimestamp = new Timestamp(anotherDate, new Time());
        this.oneClock.adjustClockTo(anotherTimestamp);
        assertEquals(anotherDate, this.oneClock.currentDate());
    }
    
    @Test
    public void aDifferentTimeAfterBeingAdjusted() {
        Time anotherTime = new Time(11, 0, 0);
        Timestamp anotherTimestamp = new Timestamp(new Date(), anotherTime);
        this.oneClock.adjustClockTo(anotherTimestamp);
        assertEquals(anotherTime, this.oneClock.currentTime());
    }
    
    @Test
    public void aDifferentTimestampAfterBeingAdjusted() {
        Timestamp anotherTimestamp = new Timestamp(new Date(1987, 1, 19), new Time(11, 0, 0));
        this.oneClock.adjustClockTo(anotherTimestamp);
        assertEquals(anotherTimestamp, this.oneClock.currentTimestamp());
    }
    
}
